import {
  batchDemandConfirmList,
  batchDemandOpen,
  batchDemandCheckList,
  delDemandByIdList,
} from '@/api/purchase-demand/supportDemandReceive';
import { info } from '@/common/utils/modal-promise';
import { Message } from '@arco-design/web-vue';

export const getBtnList = (type: string, chileType: string) => {
  const allBtn = {
    batchConfirmationBtn: {
      name: '批量确认',
      type: '7',
      isDisabled: true,
      func: batchConfirmation,
    },
    allConfirmationBtn: {
      name: '全部确认',
      type: '9',
      func: () => {
        return Promise.resolve();
      },
    },
    // allSaveBtn: {
    //   name: '保存',
    //   func: allSave,
    // },
    allDelBtn: {
      name: '删除',
      type: '8',
      isDisabled: true,
      func: allDel,
    },
    allImportBtn: {
      name: 'Excel导入',
      type: '2',
      func: () => {
        return Promise.resolve();
      },
    },
    allCheckoutBtn: {
      name: '重新校验',
      type: '10',
      isDisabled: true,
      func: allCheckout,
    },

    allCloseBtn: {
      name: '手动关闭',
      isDisabled: true,
      type: '3',
      func: () => {
        return Promise.resolve();
      },
    },
    allRecoverBtn: {
      name: '恢复手动关闭',
      type: '12',
      isDisabled: true,
      func: allRecover,
    },
    allPurchaseBtn: {
      name: '指定是否采购',
      isDisabled: true,
      type: '4',
      func: () => {
        return Promise.resolve();
      },
    },
    allImportCloseBtn: {
      name: '导入需要手工关闭的需求',
      type: '5',
      func: () => {
        return Promise.resolve();
      },
    },
  };
  const btnlist = <any>{
    '11': [
      allBtn.batchConfirmationBtn,
      allBtn.allConfirmationBtn,
      allBtn.allCheckoutBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allDelBtn,
      allBtn.allImportBtn,
    ],
    '12': [
      allBtn.batchConfirmationBtn,
      allBtn.allConfirmationBtn,
      allBtn.allCheckoutBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allDelBtn,
      // allBtn.allImportBtn,
    ],
    '13': [
      allBtn.allCloseBtn,
      allBtn.allRecoverBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allImportCloseBtn,
    ],
    '21': [
      allBtn.batchConfirmationBtn,
      allBtn.allConfirmationBtn,
      allBtn.allCheckoutBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allDelBtn,
      allBtn.allImportBtn,
    ],
    '22': [
      allBtn.batchConfirmationBtn,
      allBtn.allConfirmationBtn,
      allBtn.allCheckoutBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allDelBtn,
      // allBtn.allImportBtn,
    ],
    '23': [
      allBtn.allCloseBtn,
      allBtn.allRecoverBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allImportCloseBtn,
    ],
    '31': [
      allBtn.batchConfirmationBtn,
      allBtn.allConfirmationBtn,
      allBtn.allCheckoutBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allDelBtn,
      allBtn.allImportBtn,
    ],
    '32': [
      allBtn.batchConfirmationBtn,
      allBtn.allConfirmationBtn,
      allBtn.allCheckoutBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allDelBtn,
      // allBtn.allImportBtn,
    ],
    '33': [
      allBtn.allCloseBtn,
      allBtn.allRecoverBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allImportCloseBtn,
    ],
    '41': [
      allBtn.batchConfirmationBtn,
      allBtn.allConfirmationBtn,
      allBtn.allCheckoutBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allDelBtn,
      allBtn.allImportBtn,
    ],
    '42': [
      allBtn.batchConfirmationBtn,
      allBtn.allConfirmationBtn,
      allBtn.allCheckoutBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allDelBtn,
      // allBtn.allImportBtn,
    ],
    '43': [
      allBtn.allCloseBtn,
      allBtn.allRecoverBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allImportCloseBtn,
    ],
    '51': [
      allBtn.batchConfirmationBtn,
      allBtn.allConfirmationBtn,
      allBtn.allCheckoutBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allDelBtn,
      allBtn.allImportBtn,
    ],
    '52': [
      allBtn.batchConfirmationBtn,
      allBtn.allConfirmationBtn,
      allBtn.allCheckoutBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allDelBtn,
      // allBtn.allImportBtn,
    ],
    '53': [
      allBtn.allCloseBtn,
      allBtn.allRecoverBtn,
      // allBtn.allSaveBtn,
      allBtn.allPurchaseBtn,
      allBtn.allImportCloseBtn,
    ],
  };
  return btnlist[`${type}${chileType}`];
};
// 批量确认
const batchConfirmation = async (params: any) => {
  await info({
    title: `您确定要确认当前所选的需求？`,
    content: '',
    hideCancel: false,
  });
  const par = getParams(params);
  const res: any = await batchDemandConfirmList(par);
  if (res.code === 200) {
    Message.success('确认成功');
  }
};
// 保存
// const allSave = (params: any) => {
//   console.log('保存', params);
//   return Promise.resolve();
// };
// 删除
const allDel = async (params: any) => {
  console.log('删除', params);
  await info({
    title: '您确定要删除当前所选的需求？',
    content: '',
    hideCancel: false,
  });
  const par = getParams(params);

  const res: any = await delDemandByIdList(par);
  if (res.code === 200) {
    Message.success('删除成功');
  }
};
// 重新校验
const allCheckout = async (params: any) => {
  console.log('重新校验', params);
  const par = getParams(params);
  const res: any = await batchDemandCheckList(par);
  if (res.code === 200) {
    Message.success(res.message);
  }
};
// 恢复手动关闭
const allRecover = async (params: any) => {
  console.log('恢复手动关闭', params);
  const par = getParams(params);
  const res: any = await batchDemandOpen(par);
  if (res.code === 200) {
    Message.success('恢复手动关闭成功');
  }
};
const getParams = (params: any) => {
  const par = params.selection.map((item: any) => {
    const temp = {
      id: item.id,
      requireNo: item.requireNo,
      materialCode: item.materialCode,
      functionType: params.functionType,
      classType: params.activeTab,
      queryType: params.activeRadio,
    };
    return temp;
  });
  return par;
};

export default null;
